﻿
/*======================================================================================================\
|                                          空调零售主列表页面                                                 |
|-------------------------------------------------------------------------------------------------------|
|作者：郭建文                                                                                           |
|时间：2010-09-08 创建并注释                                                                            |
|                                                                                                       |
|说明：◆ 演示最简单基本的列表页面。                                                                    |
|      页面由单个的查询条件（form）+单个的静态表格（grid）构成                                          |
|      ◆ 演示了 查询条件中，出现了多级下拉列表联动的处理过程                                           |
|      ◆ 演示了 如何获得用户当前设置的查询条件，并发出请求，查询数据                                   |
|                                                                                                       |
|-------------------------------------------------------------------------------------------------------|
|                                                                                                       |
|                 必须严格执行代码层次缩进规范！4空格缩进！严禁tab键缩进！                              |
|                                                                                                       |
|                                       Copyright (c) 2009 YuJunJie                                     |
\======================================================================================================*/
var loginUserId;
var loginUserName;

var page1 = new Sail.page({
    name     : "mainList",                  //定义页面对象的唯一标识 名称
    mode     : 'list',                      //这只页面对象的运行模式：列表页面
	isIframe : true,
    
    frames   : {
        name     : "listFrame",                 //该frame对象的唯一标识
        title    : "数据列表",             //标题文本

        //-------------------------------------------------------------------------------
        //以JSON形式描述 frame 的构成(包含哪些 item)
        //-------------------------------------------------------------------------------
        items    : [
                {
                name  : "search",   
                type  : "form", 
                title : "查询条件",
                "isSearch" : true,
                
                "items" : [
                {
		            type:"calendar", title:"单据日期从", dataIndex:'beginBillDate'    
		        },{
		        	type:"calendar", title:"至", dataIndex:'endBillDate'     
		        },{
		        	type:"input", title:"空调名称",   dataIndex:'materielName'
		        },{
					type:"input", title:"录入人"
						
//					dataIndex : "creatorId",nameIndex : "creatorName",    
//					allowBlank:true,root:"dataset.item",fieldText:"name",fieldValue:"id",
//					url:"../../../DataDict?type=matBillCreator&cate=params&billType=" + BILL_TYPE_REPAIRS_OUTWAREHOUSE + "&businessType=" + OUTWAREHOUSE_TYPE_OF_BAOFEI
                }
		        ],
                "layoutConfig" : {
                    columns : 4
                },
                "layout" : [
                    {
                	  items:[
			                {'name':'单据日期从'},
			          	    {'name':'至'},
			          	    {'name':'空调名称'},
			          	    {'name':'录入人'}
                           ]
                    }
                ]
            },
            {
                name      : "gridMain",
                type      : "grid",
                title     : "空调零售单列表",
                tbar      : ['新增','-','删除','-'],
                pageSize:6,
            	singleSelect:false,
            	height:MAIN_HEIGHT,
                bindRelation   : {
                    root  :"dataset.billVo",
                    id    : "id",
                    field :["transactionId","creatorId","billStatus"],
                    col   :[
                        {"header":"单据日期",  "width":100,   "dataIndex":"billDate","renderer":Sail.formatDate},
                        //{"header":"仓库", "align":"left","width":150,   "dataIndex":"warehouseName" },
                        {"header":"总金额", "align":"left","width":80,   "dataIndex":"value1" },
                        {"header":"已付款", "align":"left","width":80,   "dataIndex":"value2" },
                        {"header":"欠款", "align":"left","width":80,   "dataIndex":"value3" },
                        {"header":"客户姓名", "align":"left","width":80,   "dataIndex":"value4" },
                        {"header":"联系电话", "align":"left","width":100,   "dataIndex":"value5" },
                        {"header":"录入人", "align":"left","width":80,   "dataIndex":"creatorName" },
                        {"header":"录入时间",   "width":120,   "dataIndex":"createTime","renderer":Sail.toFullDate},
                        {"header":"修改",      "width":50,   "actionCol" :true, renderer:
                        	function(value,p,r){
                 			  var creatorId = r.get('creatorId');
                 			  var billStatus = r.get('billStatus');
                 				return "<span class=actionSpan>修改</span>";
      				      }  
                        }
                    ]
                    
                }
            },
            {
                name      : "gridSub",
                type      : "grid",
                title     : "空调零售单明细",
                "colCheckbox"  : "false",
                bbar:false,
                haveCheckCol:false,
                height:SUB_HEIGHT,
                bindRelation   : {
                    root  :"dataset.billDetailVo",
                    col   :[
                        {"header":"名称规格",align:"left",  "width":250,   "dataIndex":"materielName" },
                        {"header":"单位",align:"left",  "width":80,   "dataIndex":"unitName" },
                        {"header":"单价",align:"left",  "width":80,   "dataIndex":"price" },
                        {"header":"数量",align:"left",  "width":80,   "dataIndex":"amount" },
                        {"header":"金额",align:"right",  "width":80,   "dataIndex":"money" }
                    ]
                    
                }
            }
        ],
        
        layoutConfig : {
            columns : 2,
            width:[0.65,0.35]
       	},
        
		layout : [
		    {
                items:[{'name':"search",'colspan':2}]
            },
            {
                items:[{'name':"gridMain"},{'name':"gridSub"}]
            }
        ],
        
        //-------------------------------------------------------------------------------
        //frame 的构成元素可以响应的事件的描述
        //此示例中，同时演示了查询条件中，多级 下拉列表联动 的实现
        //-------------------------------------------------------------------------------
        bindEvent2Items : function(){   
			//主、从grid
			var grid = $('gridMain');
			var subgrid = $('gridSub');
	
			//查询事件
			$('search').addButtonHandler('查询',function(){
				subgrid.removeAll();
				queryData();
		    });
			
			//重置
			$('search').addButtonHandler('重置',function(){
				setInitValue();
		    });
			
            //新增
            grid.addButtonHandler('新增',function(){
                Sail.open("retailDetail.html","add",{},MIDDLE_MODWIN_WIDTH,MIDDLE_MODWIN_HEIGHT);
                grid.load();
            });
            
            
            //删除
            grid.addButtonHandler('删除',function(){
                if(confirm("确认要删除所选择的数据吗？")){
                    var ids = grid.getSelections('transPid').join(':');
                    Sail.postData('../../../DataMap?funcname=delete',
                                {'f_transIds':ids},
                                function(flag,getData){
                                    if(flag == "true"){
                                        Ext.Msg.alert("提示","操作成功!");
                                        grid.load();
                                        subgrid.load();
                                    }
                                    else{
                                        Ext.Msg.alert("警告",getData.dataset.response.content);
                                    }
                                });
                }
            });
            
            //修改
            grid.addAction('修改',function(id){
                Sail.open("retailDetail.html","update",{"id":id},MIDDLE_MODWIN_WIDTH,MIDDLE_MODWIN_HEIGHT);
                grid.load();
            });
            
            //选择首行,显示子列表数据
            grid.on('afterload',function(){
                grid.selectFirstRow();
            });
            
            //主列表行事件,显示子列表数据
            grid.on('rowclick',function(id,row,record){
            	if (id == "") {
        			return;
        		}
        		var transactionId=record.get("transactionId");
        		if (transactionId == "") {
        			return;
        		}
          	var url = "../../purchase.do?method=listDetail&lastTransactionId="+transactionId;
          	$('gridSub').load(url);
            }); 
        }        
    },
    //进入页面自动查询数据
	afterRun : function(){
    	//设初值
    	setInitValue();
    	//查询数据
    	queryData();
	},
	
	afterLoadLoginInfo:function(){
		loginUserId = this.getUser();
		loginUserName = this.getOpername();
	}
});

page1.run();

function setInitValue()
{
	//单据日期初始化
	var beginDate = getMonthFirstDay();
	$('单据日期从').setValue(beginDate);
	var endDate=getCurrentDay();
	$('至').setValue(endDate);
	
	if (!$('gridMain').getButton("新增").disabled)
	{	
		//$('录入人').setData(loginUserId, loginUserName);
	}
}
function queryData(){
	var searchInfo = $('search').getSearch();
	var url = "../../retail.do?method=list&filter_EQS_billType.id="+BILL_TYPE_RETAIL+searchInfo;
	$('gridMain').load(url);
}

